package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import com.itheima.utils.MapperUtil;

import java.util.List;

//service 实现类
public class UserServiceImpl implements UserService {
    // 因为要用到dao层 设置一个 成员属性
    private UserDao userDao = MapperUtil.getMapper(UserDao.class);

    @Override
    public boolean register(User user) {
        boolean flag = false;
        int row = userDao.addUser(user);
        // 判断这次添加操作 影响多少行
        if(row>0){//添加成功
            flag=true;
           //提交操作
            MapperUtil.commitAndClose();
        }
        return flag;
    }
   // service完成登录
    @Override
    public User login(String username, String password) {
        User user = null;

        //通过 dao查询
        user =  userDao.login(username, password);

        return user;
    }

    @Override
    public List<User> queryAll() {
        List<User> list = null;

        list = userDao.queryAll();

        return list;
    }
}
